<?php
include 'D:/dingjiangbbs/head.php';
//屏蔽notice错误
error_reporting(E_ALL ^ E_NOTICE);

//将常量赋值给变量
$web_site = WEB_SITE;
$views_home  = WEB_SITE.'views/home/';
$admin_home  = WEB_SITE.'admin/home/';
$admin_2     = WEB_SITE.'admin/admin/';

/**************数据库操作***********************/
$table  = DB_TABLE_CG;
$fields = 'classname,cid,compere';

//遍历所有版块
$data_big = select($link,DB_TABLE_CG,'*',"order by orderby desc");
//var_dump($data_big);

/***************正确代码***********************/
//取导航头，如 内核源码
	//a标签传递的
$cid    = $_GET['classid'];
//var_dump($cid);
$fields = 'classname,cid,compere';
$where  = "where cid=$cid";
$data4  = select($link,$table,$fields,$where);
//var_dump($data4[0]['cid']);
//var_dump($data4);

/******【多表联合查询】(须有公共字段,如,uid=authirid)*****/
//$sql = select bbs_detail.title , bbs_user.username from bbs_detail left join bbs_user on bbs_detail.authorid=bbs_user.uid;
/***********************************************/
/***************分页显示***********=*****************/

//获取page的初值
//var_dump($_GET['page']);
$page   = isset($_GET['page'])?$_GET['page']:1;
//var_dump($page);

//查询板块获取总条数(由classid值决定)
$table  = DB_TABLE_DETAIL." where first=1 and classid=$cid";
$fields = id;
$total  = idCount($link,$table,$fields);
//var_dump($total);

//每页显示条数
$num    = 8; 

//共多少页
$pageTotal = ceil($total/$num);

//偏移量
$offset = $num * ($page - 1);

//根据每页显示数和偏移量查询
//$sql = select title addtime authorid from bbs_detail limit $offset,$num;

//分页排布
$table  = DB_TABLE_DETAIL;
$fields = 'title ,addtime,authorid,id,replycount,hits,rate,isdel,ishot,elite,style,istop';
$where  = "where first=1 and classid=$cid and isdel=0 order by istop desc,toptime desc, addtime desc  limit $offset,$num";
$res 	= select($link,$table,$fields,$where);
//var_dump($res);

/***********今日发帖数********************************/
//var_dump($res[0]['addtime']);
for ($i=0;$i<count($res);$i++){

	$addtime = $res[$i]['addtime'];

	if ($addtime > strtotime('00:00:00')) {

		$rows[] = $res[$i]['addtime'];
		//var_dump($rows);
		$today_count = count($rows);

		//var_dump($today_count);
	}

}

/*******************************************************/

//通过authorid==id 跨表查 username
for ($i=0;$i<$num;$i++) {
	$uid[] = $res[$i]['authorid'];
	//var_dump($res[$i]['authorid']);
}
//var_dump($uid);
foreach ($uid as $k => $v) {
	//var_dump($v);
	$uid 	= $v; 
	//var_dump($uid);
	$table  = DB_TABLE_USER;
	$fields = 'username';
	$where  = "where uid=$uid";
	$result = select($link,$table,$fields,$where);
	//var_dump($result);
	
}

//首、上、下、尾页
$prev = $page - 1;
$next = $page + 1;
if ($prev < 1) {
	$prev = 1;
}
if ($next > $pageTotal) {
	$next = $pageTotal;
}
//var_dump($num,$offset,$page,$total,$prev,$next,$pageTotal);

/*****************分页结束**********************************/

//传递参数及参数变量值
$vars = compact('web_site','views_home','admin_2','data0','data1','data2','data3','data4','today_count','num','offset','page','total','prev','next','pageTotal','res','result','data_big');

display('public.html',$vars);

//包含文件
include DOC_ROOT.'bottom.php';

